<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/8/6
  Time: 16:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>课程添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="${AppPath}/css/font.css">
    <link rel="stylesheet" href="${AppPath}/css/index.css">
    <script type="text/javascript" src="${AppPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${AppPath}/js/index.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->

</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" id="form">
            <div class="layui-form-item">
                <label  class="layui-form-label">
                    <span class="x-red">*</span>班级名称
                </label>
                <div class="layui-input-inline">
                    <select name="classId" id="classId" onchange="classId()">

                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>选择班级名称
                </div>
                <label class="layui-form-label" id="classIdmsg">

                </label>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>科目名称
                </label>
                <div class="layui-input-inline">
                    <select name="courseId" id="courseId" onchange="courseId()">

                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>选择科目名称
                </div>
                <label class="layui-form-label" id="courseIdmsg">

                </label>
            </div>
            <div class="layui-form-item">
                <label  class="layui-form-label">
                    <span class="x-red">*</span>星期
                </label>
                <div class="layui-input-inline">
                    <select name="ctWeek" id="ctWeek" onchange="ctWeek()">
                        <option value="0">请选择星期</option>
                        <option value="1">星期一</option>
                        <option value="2">星期二</option>
                        <option value="3">星期三</option>
                        <option value="4">星期四</option>
                        <option value="5">星期五</option>
                        <option value="6">星期六</option>
                        <option value="7">星期日</option>
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>选择星期
                </div>
                <label class="layui-form-label" id="ctWeekmsg">

                </label>
            </div>
            <%--<div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>角色</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="like1[write]" lay-skin="primary" title="超级管理员" checked="">
                    <input type="checkbox" name="like1[read]" lay-skin="primary" title="编辑人员">
                    <input type="checkbox" name="like1[write]" lay-skin="primary" title="宣传人员" checked="">
                </div>
            </div>--%>
            <div class="layui-form-item">
                <label for="ctTime" class="layui-form-label">
                    <span class="x-red">*</span>第几节课
                </label>
                <div class="layui-input-inline">
                    <select name="ctTime" id="ctTime">

                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    课
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button  class="layui-btn" type="button" lay-filter="add" lay-submit="" id="addBtn">
                    增加
                </button>
            </div>
        </form>
    </div>
</div>
<script src="${AppPath}/js/jquery.js"></script>
<script>
   $(function(){
       /*初始化*/
       $.ajax({
           url:"${AppPath}/coursetable/findOne",
           type:"post",
           success: function(data){
               if(data.result){
                   /*班级*/
                   let op ='';
                   op += '<option value="0">请选择班级名称</option>';
                   $.each(data.classList,function(index,clazz){
                       op += '<option value="'+clazz.classId+'">'+clazz.className+'</option>';
                   })
                   $("#classId").html(op);
                   pre();
                   /* 科目*/
                   let or ='';
                   or += '<option value="0">请选择科目名称</option>';
                   $.each(data.courseList,function(index,course){
                       or += '<option value="'+course.courseId+'">'+course.courseName+'</option>';
                   })
                   $("#courseId").html(or);
                   pre();
               }
           }
       })
      /* 第几节课*/
       let times = ['第一节','第二节','第三节','第四节'];
       let to='';
         to += '<option value="0">请选择第几节课</option>';
        $.each(times,function (index,time) {
            to += '<option value="'+(index+1)+'">'+time+'</option>';
        })
       $("#ctTime").html(to);
       pre();
       //自定义验证规则

       //监听提交
       $("#addBtn").click(function(){
           if(checkmsg()){
               $.ajax({
                   url:"${AppPath}/coursetable/add",
                   data:$("#form").serialize(),
                   type:"post",
                   success: function(data){
                       if(data.result){
                           layer.msg("增加成功",{time:2000,icon:6},function () {
                               //关闭当前frame
                               xadmin.close();
                               //重新定位到查询页面
                               xadmin.father_reload();
                           })
                       }else{
                           layer.msg("增加失败",{time:2000,icon:5,shift:6});
                       }
                   }
               })
           }
       })


   })


/*渲染*/
function pre(){
    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var  form = layui.form;
        form.render();
        // 监听全选
        form.on('checkbox(checkall)', function(data){

            if(data.elem.checked){
                $('tbody input').prop('checked',true);
            }else{
                $('tbody input').prop('checked',false);
            }
            form.render('checkbox');
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
        form.render();
    });
}
   /*表单校验*/
   function checkmsg() {
       return classId()&&courseId()&&ctWeek();
   }

   function  classId(){
       let classId = $("#classId").val();
       let msg = "<font color='red'>科目不能为空</font>";
       let flag=false;
       if (classId!=null&&classId!=0) {
           msg = "<font color='green'>ok</font>";
           flag=true;
       }
       $("#classIdmsg").html(msg);
       return flag;
   }
   function  courseId(){
       let courseId = $("#courseId").val();
       let msg = "<font color='red'>科目属性不能为空</font>";
       let flag=false;
       if (courseId!=null&&courseId!=0) {
           msg = "<font color='green'>ok</font>";
           flag=true;
       }
       $("#courseIdmsg").html(msg);
       return flag;
   }
   function  ctWeek(){
       let ctWeek = $("#ctWeek").val();
       let msg = "<font color='red'>开课时间不能为空</font>";
       let flag=false;
       if (ctWeek!=null&&ctWeek!=0) {
           msg = "<font color='green'>ok</font>";
           flag=true;
       }
       $("#ctWeekmsg").html(msg);
       return flag;
   }
</script>
<script>var _hmt = _hmt || []; (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>

